Organized code, small fixes