Code cleanup in core functions