Cleaned up some internal functions for improved readability