Refactor part 2 - most features reimplemented