Modified code for minor bug fixing