fixed bug with referencing own table
added test