Refactoring
Refactoring error checking