Added error handling and timeout options
Fixed for safari and chrome
Even more cleaning to work properly, hate javascript!