cleaned up code structure