organized code a bit for readability