added som comments in main() and have possibly discovered an error?
added more comments