added length check, removed useless returns