Change all callbacks to objects with types

It ill make error handling easier to do and understand
Add error message in options
Add document closing and console clearing