Finished JavaScript Logic