More cleaning up to the main class.

Improved errors to have better messages