Cleaner code and recursive function