refactor rectangle encoding a bit