Re-enable clock, logic probably still doesn't work. Move variables that don't need to be global. Redo the visibility led switch in a interrupt, since it is more time sensitive.