Add associations, small code refactoring