cleaned up javascript functions