altered code layout; need to make it easy to test functions independently