moved around source, fixed compiler warnings