Adding comments and exceptions

Adding comments and exceptions to improve program structure