Patricia recoded. Much more clear logic