cleanup and other argument checking improvements