refactored everything and created meaningful error messages