Added loader, error messages and made some code cleanup