Code rewrite, documentation, unit tests