improved clear method, improved main method