added tests and minor changes

some math simplified further