swapped a and b correctly so as to make calculations correct