adding tests and fixing misc issues