minimized code a little + minor changes