imrove error checking, style changes and pasting issues