Revert "use ternary operator" and tons of cleanup

This reverts commit 8059df8f58868507ff23a01fb1ec603b60b5e9ad.