Fix menu levels and tidy up the code

The maxDepth is 1 increased at some line. It cause for the problem of
exceeding the expected level's number.