refactoring in jquery style
fixed issues with editing