refactored and optimized, cleaned tests