reorganized boundary checks and fixed controls bugs