Fixes bug when record is nil
Small test refactor
Logic refactor