Add detection of unused/duplicated key, refactor and break code into modules