added much needed tests and squashed related bugs