major refacoring and simplyfying