updated code to be a bit easier to read