Improve design, fix bug with page size, simplify an algorithm