Refactor Items per page calculation