cleaned up all code, fixed up resource script to work on client side