cleaning and consolidating and functions for final version of code