cleaned up thecode a bit