some checks and cleanup