Could the two functions in here not share some of the same code? I also noticed that both have different styles for similar lines of code.