Final version to submit; Added detailed comments and broke code into small chunks.