backend mostly done

unit tests included