Reduced the code somewhat