cleaned up functions and use new version of jquery