Fix formatting, add if tests, cleanup