removed old code + added length check