Refactoring & error handling

every layer