Finally completely working version