added overflow protection