added tests. fixed bugs. shortened code