slightly cleaned up code