Added a lot error and class checking