Small code restructure. Also added "resize" functionality.