removed multi-returns from several functions, and improved code generally