re-arranged js a bit