Code cleanup and improve