Refactoring and added new exception class