fix for not being able to turn off next alarm
refactoring and critical bug fixes