Completed with some refactoring.
More refactoring, added dynamic error checking