Reduced complexity and added tests