Code cleanup and Misc Functions

Fixed some minor issues, now somewhat stable