clean up a bit, but the code still is a mess