slight front and back end refactoring; fix small bugs