refactored boundary check and re-immutabled canvas