major refactoring :) getting smarter