Updated with more tests and made tests modular

This is a strange mix of sync and async code... Can we just do it async and make the callback take an err parameter?