Tested solution, seems to work