working version
removed some logging