bunch of cleanup, reorganization, and get alarm/wakeup to work