Clean up, code standards, improved logic