Fix errors and apply hlint suggestions