Converted javascript to Library format