JS closure to fit all the code, helpers and basic constructor