Solution for a project at work, modified for reuse