cleaned up code a bit more, based on Yash's comments