improved front-end javascript and added conditional to backend js