Made posibly working mySQL functions, improved tp function