Small conditional check in case someone has removed the animations property.
Pretty huge refactoring to cut down on duplicated code.
jshint fixes and tidying up for release