cleaned up code, added code to stop after 3 min