Fixed interrupt problems. Added critical section handling.