rewrote code to not reload page