refactorings for more general use
removed dependencies and added comments