Changed logic to typeswitch and added comments.