Organized code, fixes