Fixed logic error in cube function