revise flags handling; implement relocation; refactoring