Streamlined javascript code