Major refactoring + fixing validation errors