Manually merged in Ahsan's code