Fix resizing and do some code cleanup