Core overflow detection

Added overflow detection, but it needs to be improved.