Fixed switching bug (now works as intended)
Cleaned up code and added more descriptive comments.