Import more code and cleanup some useless things