Modified the code to be more straight forward.