changed around logic, fixed several syntax errors from last commit