Implemeted check_preempt and fixed a few bugs