Improved code readabilty and fixed minor issues