More error handling and createPolynomial function