-added bound to input length
-added error logging