Add unit tests
Modularise code