Replaced recursive function calls by queue. Added python bindings.