Refactor to support sbt and add unit tests