added some much-needed tests and modularity