re-factory the code