Cleaned up helper functions a bit