Some initial error handling, refactoring
Merging