refined the main app loop, command matching and sample module