moved most of the logic to the first page