Modified to compile under OS X. Added reset functionality