almost done, need to clean up and comment the code