Added collapse method, put main in class