before giving this out to the OP, might as well put it here for everyone. the bulk of the code is not mine, just added some good feature.