Code improvements

@bear Read line 37. I will merge as I know I didn't break anything.