added comments and cleaned up a few things, main only works if preceded by function