changed javascript to jquery where possible