did some cleanup and made the functions work a bit more intuitively