Separate some concerns, fix tests