reworked first problem to remove redundant variables