change back to milliseconds (seems more reliable) and fix one small bug