cleanup, optimise demap from giovanni and use it instead of mine