Doing improvements on the code as suggested by Thomas.