Rewrited and added main function