result variable was used before assignment. Also fixed unnecessary code for len check of result since when it is not set in if call above we can directly return an empty list