completion of hw3, although without reducing verbosity