Cleaned up code. Logical grouping in function, more descriptive variable names