final solution, somehow correct