Some refactorizing and removing redundant code