cleanup of code after better understanding. Performance stays the same if not better