compacted memory clean up code a bit