Ported from my java assignment: first to accomplish this!