bug fixes and toggle function