Cleaned up the code, removed deprecated functions