Improved Energy function