Cleanup complex code