More efficient RAM usage, TODO: fix code dup