Add comments, fix formatting, improve logging (#466)