refactored backend largely