Refactors js and adds cancel button