Made some tweaks to the code