Improve various aspect of the code

I've cleanup a couple of things and started reorganizing the methods.