Code cleanup and more NET4 modifications