some cleanup and readability of javascript code in order to find the problem why selected are not checked