Working setup function

Also got rid off compiler warnings.