Resized and reworked code