Minor tweaks and make the code a bit more flexible by allowing it to take arguments from command line.