Fix bug with variables handling, and some extra debug logging