working code finalized backend refactoring