Code cleaned based on PilzAdam work on https://github.com/minetest/minetest_game/pull/375/