Fixed main method, writting auxiliary methods