Code review and some improvements