cleaned up conditionals and added a few comments