Added toggle function and tidied up returns