refactored magic numbers into val and var; added assert