Added a function to determine active element