bugfixing and added tests