Fix quantity bugs

See commits for details.