More functional than previous commit but still needs more tweaking