adapted geovanecomp's commits 93883ed-3138c9dce