made changes to toggle function and also troubleshooted