Code cleanup and some extras