fixed undefined error for remaining amount by catching TypeError