Nothing appears to be wrong with that code in your first post apart from the booleans need to be initialised.