Implemented status machine in the main