code fixed, added some new functions