sequential code (inefficient, might look into fixing it) debugged