Basic error handling added and minor refactoring