Slightly cleaned up code