Clean code, add comments, fix settheme function