Fixed logic error in getting free memory