Fixed toggling and other major refactoring