Cleaning code + handling errors