Initial draft
Fixed tests and reformatted code