Reduced complexity, added tests