some cleaing, added more checks