added defensive coding