first commit, includes error catching and AMD definition