removed debug statements
added type check