refactoring to service and seperate files