cleaned up reusable code from mp2