refactored some small inefficiencies