update the code for better structure