Reduce JS needed and add error handling