added tests and moved most of shared functions over