finally the code is in a good shape